﻿#region Using Directives

using System;
using System.Web.Security;
using System.Collections.Generic;

using QuickDev.Common.Utils;
using QuickDev.Common.Serialization;

using QuickDev.Model;
using QuickDev.SQLServerDAL;
using QuickDev.Caching;

#endregion

namespace QuickDev.BLL
{
    /// <summary>
    /// BLL Layer For dbo.OPM_ReturnOrderMemo.
    /// </summary>
    public class ReturnOrderMemoBLL
    {
        #region ReturnOrderMemoBLL.Insert( int returnOrderId , string memo , int createdBy ) Method

        /// <summary>
        /// public static int Insert( int returnOrderId , string memo , int createdBy )
        /// </summary>
        /// <param name="returnOrderId">returnOrderId</param>
        /// <param name="memo">memo</param>
        /// <param name="published">published</param>
        /// <param name="createdBy">createdBy</param>
        /// <returns>ReturnOrderMemo model</returns>
        public static ReturnOrderMemo Insert( int returnOrderId , string memo , int createdBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( returnOrderId , "QuickDev.BLL.ReturnOrderMemoBLL.Insert() Method -- returnOrderId" );
            Validation.ValidateStringArgumentIsNotNullOrEmptyString( memo , "QuickDev.BLL.ReturnOrderMemoBLL.Insert() Method -- memo" );

            int newId = ReturnOrderMemoDAL.Insert( returnOrderId , memo , createdBy );

            if ( newId > 0 )
            {
                ReturnOrderMemoCache.RemoveAllCollectionFromCache();

                return ReturnOrderMemoCache.GetModel( newId );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderMemoBLL.UpdateStatus( int id , bool published , int updatedBy ) Method

        /// <summary>
        /// public static bool UpdateStatus( int id , bool published , int updatedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="published">published</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>ReturnOrderMemo model</returns>
        public static ReturnOrderMemo UpdateStatus( int id , bool published , int updatedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderMemoBLL.Update() Method -- id" );

            if ( ReturnOrderMemoDAL.UpdateStatus( id , published , updatedBy ) )
            {
                ReturnOrderMemoCache.RemoveAllCollectionFromCache();
                ReturnOrderMemoCache.RemoveModelFromCache( id );

                return ReturnOrderMemoCache.GetModel( id );
            }
            else
            {
                return null;
            }
        }
        #endregion

        #region ReturnOrderMemoBLL.Delete( int id , int deletedBy ) Method

        /// <summary>
        /// public bool Delete( int id , int deletedBy )
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="updatedBy">updatedBy</param>
        /// <returns>bool successful</returns>
        public static bool Delete( int id , int deletedBy )
        {
            Validation.ValidateIntegerIsGreaterThanZero( id , "QuickDev.BLL.ReturnOrderMemoBLL.Delete -- id" );

            if ( ReturnOrderMemoDAL.Delete( id , deletedBy ) )
            {
                ReturnOrderMemoCache.RemoveAllCollectionFromCache();

                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion
    }
}

